package com.media.api;

import com.base.model.R;
import com.media.model.Publish;
import com.media.model.PublishRecode;
import com.media.model.User;
import com.media.service.PublishRecodeService;
import com.media.service.PublishService;
import com.media.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 小何
 * @Description: TODO
 * @DateTime: 2023/9/21 10:59
 **/
@RestController
@RequestMapping("/publish")
@Api(tags = "预发布接口")
public class PublishController {

    @Autowired
    private PublishService publishService;

    @Autowired
    private PublishRecodeService publishRecodeService;

    @ApiOperation("查询所有预发布视频信息")
    @PostMapping(value = "/listPublish/{page}/{pageSize}")
    @PreAuthorize("hasAuthority('listPublish')")
    public R<List<PublishRecode>> listPublish(@PathVariable Integer page, @PathVariable Integer pageSize, @RequestBody Publish publish) {
        return publishRecodeService.listPublishRecord(page,pageSize,publish);
    }


    /**
     * 审核通过
     *
     * @param publishId 视频Id
     * @return 返回字符串
     */
    @ApiOperation("审核员确认视频审核通过")
    @PostMapping(value = "/auditAccess/{publishId}")
    @PreAuthorize("hasAuthority('auditAccess')")
    public R<String> auditAccess(@PathVariable String publishId) {
        //1.从SpringSecurity中获取审核员Id
        User user = SecurityUtils.getUser();
        Integer auditorId=user.getId();
        return publishService.auditAccess(publishId, auditorId);
    }

    @PostMapping(value = "/auditFailed/{publishId}")
    @PreAuthorize("hasAuthority('auditFailed')")
    public R<String> auditFailed(@PathVariable String publishId, @RequestBody String reason) {
        //1.从SpringSecurity中获取审核员Id
        User user = SecurityUtils.getUser();
        Integer auditorId=user.getId();
        return publishService.auditFailed(publishId, reason, auditorId);
    }


    @PostMapping(value = "/transcodeSuccess")
    public R<String> transcodeSuccess(@RequestParam("publishId")String publishId){
       return publishRecodeService.transcodeSuccess(publishId);
    }
}
